#include<bits/stdc++.h>
#define int long long 
using namespace std;

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while(ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
	while(ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}
int __stk[128], __top;
inline void write(int x) {
    if(x < 0) putchar('-'), x = -x;
	do { __stk[++__top] = x % 10, x /= 10; } while(x);
	while (__top) putchar(__stk[__top--] + '0');
}
bool stmer;
const int N = 1e6 + 10, mod = 1e9 + 7;
void add(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = x * y % mod; }
int n;
int fa[N], t[N][2], ans[N];
namespace sub1 {
	int ch[N][2];
	int get(int x) { return ch[fa[x]][1] == x; }
	void rotate(int x) {
		int f1 = fa[x], f2 = fa[f1], k = get(x);
		if(f2) ch[f2][get(f1)] = x; fa[x] = f2;
		ch[f1][k] = ch[x][!k], fa[ch[f1][k]] = f1;
		ch[x][!k] = f1, fa[f1] = x;
	}
	void splay(int x) {
		for(int f; f = fa[x]; rotate(x))
			if(fa[f]) rotate(get(f) == get(x) ? f : x);
	}
	void calc(int x, int dep) {
		ans[x] += dep, dep++, fa[x] = 0;
		if(ch[x][0]) calc(ch[x][0], dep);
		if(ch[x][1]) calc(ch[x][1], dep);
	}
	void solve() {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				ch[j][0] = t[j][0], ch[j][1] = t[j][1];
				fa[t[j][0]] = fa[t[j][1]] = j;
			} fa[0] = 0, splay(i), calc(i, 0);
		}
		for(int i = 1; i <= n; i++) write(ans[i]), putchar('\n');
	}
}
namespace sub2 {
	struct node {
		int x, s;
		node operator + (const node &p) const {
			return {x + p.x, s + p.s};
		}
	};

}
bool edmer;
signed main() {
	freopen("dream.in", "r", stdin);
	freopen("dream.out", "w", stdout);
	cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
	n = read();
    for(int i = 1; i <= n; i++) t[i][0] = read(), t[i][1] = read();
	if(n <= 2e3) sub1 :: solve();
	else sub1 :: solve();
    cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds";
	return 0;
} 